<!-- import 'ant-design-vue/dist/antd' -->
<template>
  <div id="app2">
    <div>
      <input v-model="data.username" type="text" placeholder="输入名字" />
      <input v-model="data.usertype" type="text" placeholder="输入类型" />
    </div>
    <!-- <router-view> -->
    <div>
      <el-button type="primary" v-on:click="getuserlist">点击</el-button>
    </div>
    <div v-for="user in UserList.data.data" v-bind:key="user.id">
      {{ user }}
    </div>
    <!-- </router-view> -->
  </div>
</template>

<script>
// import axios from '../api/axios'
import { getItemList } from "@/api";
import { ref, provide, reactive } from "vue";
export default {
  name: "UserList",
  props: {
    da: String,
  },
  setup() {
    let data = ref({
      username: "js2",
      usertype: 1,
    });
    let UserList = reactive({
      data: {},
    });
    // let UserList = ""
    provide("loginres", "hhhh");
    function getuserlist() {
      getItemList(data.value.username, data.value.usertype)
        .then((res) => {
          // console.log(req)
          console.log(res.data.code);
          // console.log(this.username)
          if (res.data.code == 0) {
            UserList = res.data;
            console.log(UserList);
          } else {
            throw res.data;
          }
        })
        .catch((error) => {
          console.log(error);
        });

      // if (aa.status == 200){
      //   console.log(aa.status)
      // }

      //   axios
      // .get('/api/user/list/')
      // .then(response => (this.hehe = response.data))
    }
    return {
      data,
      UserList,
      getuserlist,
    };
  },
};
</script>

<style>
#app1 {
  /* display: flex;
  justify-content: space-around; */
  text-align: left;
  display: flex;
  /* flex-direction: column;
  justify-content: center;
  align-items: center; */
}
.haha {
  display: block;
}
/* button {
  text-align: center;
  height: 35px;
  cursor: pointer;
  border: none;
  outline: none;
  background: gray;
  color: whitesmoke;
  border-radius: 5px;
  width: 60px;
} */
</style>

